from django.shortcuts import render
from django.utils import timezone

from rest_framework.decorators import api_view, permission_classes
from rest_framework.permissions import AllowAny, IsAuthenticated

from drf_spectacular.utils import extend_schema, extend_schema_view, OpenApiParameter, inline_serializer
from drf_spectacular.types import OpenApiTypes

from core.response import AppResponse

from .models import Banner
from .serializer import BannerSerializer


# Create your views here.
@extend_schema(
    description='获取当前系统轮播图', 
    request=None,
    responses=BannerSerializer(many=True)
)
@api_view(['GET'])
@permission_classes([AllowAny])
def banners(request):
    banners = Banner.objects.filter(enable = True, start_time__lte=timezone.now(), end_time__gte=timezone.now()).order_by('order')
    serializer = BannerSerializer(banners, many = True, context = {'request': request})
    return AppResponse(serializer.data)


